const app = getApp();

Page({
  data: {
    payments: []
  },

  onLoad() {
    this.loadPaymentHistory();
  },

  onShow() {
    this.loadPaymentHistory();
  },

  async loadPaymentHistory() {
    try {
      const payments = await app.request('/payments/history', 'GET');
      this.setData({ payments });
    } catch (error) {
      console.error('加载支付记录失败:', error);
      wx.showToast({ title: '加载失败', icon: 'none' });
    }
  },

  getStatusText(status) {
    const statusMap = {
      'pending': '待支付',
      'completed': '支付成功',
      'failed': '支付失败'
    };
    return statusMap[status] || status;
  },

  formatTime(dateString) {
    const date = new Date(dateString);
    return date.toLocaleString();
  }
});